package org.example.maven.pojo.list;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

@Data
public class ListTableCollectionAddDetail {
    private Integer id;
    // 使用 @JsonProperty 确保 JSON 映射
    @JsonProperty("internalId")
    private String internalId;
    private String classificationId;
    private String eraId;
    private String name;
    private LocalDateTime createdAt;
    private String alternateName;
    private String description;
    private PreservationStatus preservationStatus = PreservationStatus.完好;
    private BigDecimal weight;
    private String currentLocation;
    private CollectionStatus status = CollectionStatus.在库;
    private String img;

    private transient CompletableFuture<String> imgFuture; // 临时存储上传任务

    // 添加结果处理方法
    // 修改set方法直接接受Future
    public void setImgFuture(CompletableFuture<String> imgFuture) {
        this.imgFuture = imgFuture;
        // 添加回调自动设置img字段
        imgFuture.thenAccept(url -> this.img = url);
    }



    // 保存状态枚举
    /*public  enum PreservationStatus {
        完好, 轻微损伤, 严重损伤, 修复中
    }*/
    public  enum PreservationStatus {
        完好("完好"),
        轻微损伤("轻微损伤"),
        严重损伤("严重损伤"),
        修复中("修复中");

        private final String chineseName;

        PreservationStatus(String chineseName) {
            this.chineseName = chineseName;
        }

        public String getChineseName() {
            return chineseName;
        }
        public static ListTableCollectionAddDetail.PreservationStatus fromChineseName(String chineseName) {
            for (ListTableCollectionAddDetail.PreservationStatus status : values()) {
                if (status.chineseName.equals(chineseName)) {
                    return status;
                }
            }
            throw new IllegalArgumentException("无效的保存状态iiiii: " + chineseName);
        }
    }

    // 藏品状态枚举
    public enum CollectionStatus {
        在库("在库"),
        展出("展出"),
        外借("外借"),
        修复中("修复中"),
        已注销("已注销");
        private final String chineseName;

        CollectionStatus(String chineseName) {
            this.chineseName = chineseName;
        }
        public String getChineseName() {
            return chineseName;
        }
        public static ListTableCollectionAddDetail.CollectionStatus fromChineseName(String chineseName) {
            for (ListTableCollectionAddDetail.CollectionStatus status : values()) {
                if (status.chineseName.equals(chineseName)) {
                    return status;
                }
            }
            throw new IllegalArgumentException("无效的保存状态eeee: " + chineseName);
        }
    }
}
